﻿using System;
using System.Collections.Generic;

namespace DOJ.LEISP.LEXS.Common.Providers
{
    /// <summary>
    /// Default Meta Data Provider Implementation used for sample service.
    /// </summary>
    public class DefaultMetadataProvider : ISRMessageMetadataProvider
    {
        #region IMetaDataProvider Members

        public SRMessageMetadataType GetMetaData(SRMessageMetadataType incomingMetadata)
        {
            SRMessageMetadataType metaData = new SRMessageMetadataType
            {
                MessageSequenceNumber = Utilities.MessageSequenceNumberGenerator.GetSequenceNumber().ToString(),
                MessageDateTime = DateTime.Now,
                LEXSVersion = "3.1.4",
                MessageOriginMetadata = GetSystemMetaData(),
                MessageDestinationIdentifier = GetRemoteSystemList(incomingMetadata).ToArray()
            };
            return metaData;
        }

        #endregion

        #region Helper Methods

        private static DataContactType GetSystemContact()
        {
            DataContactType systemContact = new DataContactType
            {
                PersonGivenName = "Chris",
                PersonSurName = "Deweese",
                Items = GetSystemContactTelephone().ToArray()
            };
            return systemContact;
        }

        private static List<TelephoneNumberType> GetSystemContactTelephone()
        {
            List<TelephoneNumberType> contactPhoneList = new List<TelephoneNumberType>();
            TelephoneNumberType contactPhone = new TelephoneNumberType();
            FullTelephoneNumberType phone = new FullTelephoneNumberType { TelephoneNumberFullID = "314-555-1212" };
            List<ComplexObjectType> phoneList = new List<ComplexObjectType>();
            phoneList.Add(phone);
            contactPhone.Items = phoneList.ToArray();
            contactPhoneList.Add(contactPhone);

            return contactPhoneList;
        }
        private static SystemMetadataType GetSystemMetaData()
        {
            SystemMetadataType systemMeta = new SystemMetadataType { SystemIdentifier = new SystemIdentifierType() };
            systemMeta.SystemIdentifier.SystemID = "SysE";
            systemMeta.SystemIdentifier.OrganizationName = "Hypothetical Organization E";
            systemMeta.SystemContact = GetSystemContact();

            return systemMeta;
        }

        private static List<SystemIdentifierType> GetRemoteSystemList(SRMessageMetadataType incomingMetaData)
        {
            List<SystemIdentifierType> remoteSystem = new List<SystemIdentifierType>();
            remoteSystem.Add(incomingMetaData.MessageOriginMetadata.SystemIdentifier);
            return remoteSystem;
        }
        #endregion
    }
}
